package com.loyal.mwm.ui

import android.view.View
import com.loyal.mwm.R
import com.loyal.mwm.base.BaseSwipeActivity
import com.loyal.mwm.databinding.ActivityVoiceBinding
import com.loyal.mwm.util.BdttsUtil
import com.loyal.mwm.util.MemoryUtil
import com.loyal.mwm.util.ImageUtil

class VoiceActivity : BaseSwipeActivity<ActivityVoiceBinding>(), View.OnClickListener {
    private val bdttsUtil = BdttsUtil()

    override fun actLayoutRes(): Int {
        return R.layout.activity_voice
    }

    override fun setEdgePosition(): Int {
        return LEFT
    }

    override fun afterOnCreate() {
        val toolbar = binding.toolbar.root
        toolbar.setTitle(R.string.action_voice)
        setSupportActionBar(toolbar)
        binding.drawable = ImageUtil.getBackground(this)
        MemoryUtil.mkPkgDirs()
        bdttsUtil.initTTs(this)
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.button -> speak()
        }
    }

    private fun speak() {
        val text: String = getString(R.string.album_permission_storage_failed_hint)
        //需要合成的文本text的长度不能超过1024个GBK字节。
        bdttsUtil.stop()
        bdttsUtil.speak(text)
    }
}